#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
// 7-1分段函数
int test3_7_1()
{
    float m;

    scanf("%f", &m);
    if (m < 0)
        m = fabs(m);

    else if (m < 2)
        m = sqrt(m + 1);

    else if (m < 4)
        m = pow(m + 2, 5);

    else if (m >= 4)
        m = m * 2 + 5;

    printf("%.2f", m);

    return 0;
}

// 组合数
int test3_7_2()
{
    for (int i = 1; i < 5; i++)
        for (int j = 1; j < 5; j++)
            for (int k = 1; k < 5; k++)
                if (i != j && i != k && j != k)
                    printf("%d%d%d\n", i, j, k);
}

// 7-3 回文串I
int test3_7_3_pointer()
{
    char str[81];
    gets(str);
    char *i = str;
    char *j = str + strlen(str) - 1;

    while (i <= j)
    {
        if (*i++ != *j--)
        {
            printf("NO");
            return 0;
        }
    }

    printf("YES");

    return 0;
}

int test3_7_3_array()
{
    char str[81];
    gets(str);
    int n = strlen(str);
    for (int i = 0; i < n / 2; i++)
    {
        if (str[i] != str[n - i - 1])
        {
            printf("NO");
            return 0;
        }
    }

    printf("YES");

    return 0;
}

// 7-4 二进制奇偶交换
void test3_7_4_bitwise()
{
    unsigned int n;
    scanf("%u", &n);
    n = ((n & 0x55555555) << 1) | ((n & 0xaaaaaaaa) >> 1);
    printf("%u", n);
}

void test3_7_4_array()
{
    unsigned int n;
    scanf("%u", &n);

    int a[32] = {0};
    for (int i = 0; n > 0 && i < 32; i++)
    {
        a[i] = n % 2;
        n /= 2;
    }
    unsigned int pow = 1;
    for (int i = 0; i < 32; i += 2)
    {
        n += pow * (2 * a[i] + a[i + 1]); // swap a[i] + 2*a[i+1] --> 2*a[i] + a[i+1]
        pow *= 4;                         // pow --> [1] 2 [4] 8 [16] 32 [64] 128
    }
    printf("%u", n);
}

// 7-5 最近的点
typedef struct
{
    int x, y;
    int len;
} Point;

int cmp(const void *a, const void *b)
{
    return ((Point *)a)->len - ((Point *)b)->len; // to do
}

int compare(Point p1, Point p2)
{
    return p1.len > p2.len;
}

void swap(Point *p1, Point *p2)
{
    Point p = *p1;
    *p1 = *p2;
    *p2 = p;
}

void bubble_sort(Point a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < n - i - 1; j++)
        {
            if (compare(a[j], a[j + 1]) > 0)
                swap(&a[j], &a[j + 1]);
        }
    }
}

int test3_7_5()
{
    Point points[1000];
    int n, k;

    scanf("%d%d", &n, &k);

    for (int i = 0; i < n; i++)
    {
        scanf("%d%d", &points[i].x, &points[i].y);
        points[i].len = points[i].x * points[i].x + points[i].y * points[i].y;
    }

    qsort(points, n, sizeof(Point), cmp);
    // bubble_sort(points, n);

    for (int i = 0; i < k; i++)
    {
        printf("%d %d\n", points[i].x, points[i].y);
    }

    return 0;
}

int main()
{
    return 0;
}